package com.zhupanlin.zhyl.hosp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhupanlin.zhyl.common.exception.Zhylxception;
import com.zhupanlin.zhyl.common.result.ResultCodeEnum;
import com.zhupanlin.zhyl.hosp.mapper.HospitalSetMapper;
import com.zhupanlin.zhyl.hosp.service.HospitalSetService;
import com.zhupanlin.zhyl.model.hosp.HospitalSet;
import com.zhupanlin.zhyl.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/11/15 23:10
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {


    /**
     *     根据医院编码，查询签名
     * @param hoscode
     * @return
     */
    @Override
    public String getSignKey(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        return hospitalSet.getSignKey();
    }

    /**
     * 获取医院签名信息
     *
     * @param hoscode
     * @return
     */
    @Override
    public SignInfoVo getSignInfoVo(String hoscode) {
        QueryWrapper<HospitalSet> wrapper = new QueryWrapper<>();
        wrapper.eq("hoscode", hoscode);
        HospitalSet hospitalSet = baseMapper.selectOne(wrapper);
        if (hospitalSet == null) {
            throw new Zhylxception(ResultCodeEnum.CODE_ERROR);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
